package com.film.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.film.dao.ClassifiedFilmDao;
import com.film.dao.DirectorDao;
import com.film.dao.FilmTypeDao;
import com.film.dao.PerformerDao;
import com.film.dao.impl.ClassifiedFilmDaoImpl;
import com.film.dao.impl.DirectorDaoImpl;
import com.film.dao.impl.FilmTypeDaoImpl;
import com.film.dao.impl.PerformerDaoImpl;
import com.film.domain.Film;
import com.film.service.ClassifiedFilmService;

public class ClassifiedFilmServiceImpl implements ClassifiedFilmService {
	private	ClassifiedFilmDao classifiedFilmDao = new ClassifiedFilmDaoImpl();
	private DirectorDao dirDao = new DirectorDaoImpl();
	private PerformerDao perDao = new PerformerDaoImpl();
	private FilmTypeDao typeDao = new FilmTypeDaoImpl();
	@Override
	public List<Film> selectClassifiedFilms(String title,String types,String area,String years,String sortFlag) {
		
		//通过三个字段查询相对应的电影  在通过电影的id查询其余的信息
		List<Film> lists = classifiedFilmDao.selectClassifiedFilm(title, types, area, years,sortFlag);
		List<Film> films = new ArrayList();
		//循环遍历取得Film_id用来做导演  演员  类型的查询
		for(Film f:lists) {
			f.setPerformers(perDao.selectFilmPerformer(f.getFilmId()));
			f.setDirectors(dirDao.selectFilmDirector(f.getFilmId()));
			f.setFilmTypes(typeDao.selectFilmType(f.getFilmId()));
			films.add(f);
		}
		return films;
	}
	@Override
	public List<Film> limitSelectClassifiedFilm(String title, String types, String area, String years, int pageNum,String sortFlag) {
		int stripNum = 18;//默认分页的查询条数为5条
		
		int pageNums = (pageNum-1)*stripNum;
		
		//通过三个字段查询相对应的电影  在通过电影的id查询其余的信息
		List<Film> lists = classifiedFilmDao.limitSelectClassifiedFilm(title, types, area, years,pageNums,stripNum,sortFlag);
		List<Film> films = new ArrayList();
		//循环遍历取得Film_id用来做导演  演员  类型的查询
		for(Film f:lists) {
			f.setPerformers(perDao.selectFilmPerformer(f.getFilmId()));
			f.setDirectors(dirDao.selectFilmDirector(f.getFilmId()));
			f.setFilmTypes(typeDao.selectFilmType(f.getFilmId()));
			films.add(f);
		}
		return films;
	}

}
